package org.example.springboot_threadpool_demo;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.concurrent.TimeUnit;

@Service
public class ScheduledService {
    @Scheduled(fixedRate = 3000)
    @Async
    public void fixedRate() {
        System.out.println("fixedRate thread name " + Thread.currentThread().getName() + " start at " + new Date());
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    @Async
    @Scheduled(fixedRate = 2000)
    public void fixedRate2() {
        System.out.println("fixedRate2 thread name " + Thread.currentThread().getName() + " start at " + new Date());
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
